package com.shenyue.nbtownlet.activity;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.os.Handler;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.shenyue.nbtownlet.R;
import com.shenyue.nbtownlet.adapter.ProjectFundListViewAdapter;
import com.shenyue.nbtownlet.base.BaseActivity;
import com.shenyue.nbtownlet.databinding.ActivityProjectFundBinding;
import com.shenyue.nbtownlet.model.DefaultModel;
import com.shenyue.nbtownlet.util.StringUtil;

/**
 * 项目资金
 */

public class ProjectFundActivity extends BaseActivity{
    private ActivityProjectFundBinding binding;
    private Context mContext;
    private ProjectFundListViewAdapter listViewAdapter;
    private Handler mHandler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle bundle = getIntent().getExtras();
        String name = bundle.getString(DefaultModel.PAGE_NAME);
        final String data = bundle.getString(DefaultModel.PAGE_DATA);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_project_fund);
        setActionBar(true, name);
        mContext = this;

        listViewAdapter = new ProjectFundListViewAdapter(mContext);
        binding.listView.setAdapter(listViewAdapter);

        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                init(data);
            }
        }, 32);
    }

    private void init(String data){
        JSONArray array = new JSONArray();
        String[] s = data.split("\\|");
        for (int i = 0, j = s.length; i < j; i++) {
            String str = s[i];
            if(StringUtil.isNull(str))
                continue;
            String[] args = str.split(",");
            JSONObject item = new JSONObject();
            item.put("amount", args[1]);
            item.put("time", args[2].split(" ")[0]);
            item.put("source", args[3]);
            item.put("czr", args[5]);
            item.put("czsj", args[6].split(" ")[0]);
            array.add(item);
        }
        listViewAdapter.addItems(array);
    }
}
